package com.ld.admin.controller.oa.work;

import com.ld.admin.controller.AdminBasicController;
import com.ld.admin.model.oa.work.MonthlyReportModel;
import com.ld.admin.service.oa.work.MonthlyReportService;
import com.ld.admin.service.oa.work.TodayTaskService;
import com.ld.shieldsb.annotation.duplicate.SubmitRequestIntercept;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.web.util.Web;
import com.ld.shieldsb.dao.model.QueryModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * @ClassName MonthlyReportController
 * @Description 工作月报
 * @Author 付信豪
 * @Date 2019/8/20 9:44
 * @ModifyDate 2019/8/20 9:44
 * @Version 1.0
 */
@Api(tags = "工作月报")
@Controller(value = "")
@RequestMapping("${shieldsb.adminPath}/oa/work/monthlyReport")
public class MonthlyReportController extends AdminBasicController<MonthlyReportModel> {
    @Autowired
    private MonthlyReportService monthlyReportService;
    @Autowired
    protected TodayTaskService todayTaskService;
    @ApiOperation(value = "首页", notes = "")
    @RequestMapping(path = "", method = RequestMethod.GET)
    public String index() {
        todayTaskService.permission();
        return "a/oa/work/monthlyreport/monthlyreport_header";
    }
    @ApiOperation(value = "到搜索页面", notes = "")
    @RequestMapping(path = "/toSearch", method = RequestMethod.GET)
    public String toSearch(HttpSession session, String sign) {
        session.setAttribute("monthSign", sign);  // 存入自己下级全部的页签标识
        monthlyReportService.initializeSearchDate(sign);//根据条件是否初始化搜索开始日期
        todayTaskService.getUserListBySign(sign);
        monthlyReportService.getTimeInterval(); //设置时间
        return "a/oa/work/monthlyreport/monthlyreport_search";
    }

    @ApiOperation(value = "搜索结果", notes = "")
    @RequestMapping(path = "/search", method = RequestMethod.POST)
    public String search(HttpSession session, String month) {
        String sign = (String) session.getAttribute("monthSign");
        QueryModel queryModel = monthlyReportService.getSearchQueryModel(request);
        todayTaskService.getTaskBySign(sign, queryModel);
        monthlyReportService.getPageBean(request, getModelClass(), queryModel);
        return "a/oa/work/monthlyreport/monthlyreport_list";
    }

    @ApiOperation(value = "工作月报展示", notes = "")
    @RequestMapping(path = "/show", method = RequestMethod.GET)
    public String show() {
        long id = getLong("id");
        monthlyReportService.getOne(request, getModelClass(), id);
        return "a/oa/work/monthlyreport/monthlyreport_show";
    }
    @ApiOperation(value = "跳转到添加/修改工作月报", notes = "")
    @RequestMapping(path = "/toAddOrUpdate", method = RequestMethod.GET)
    public String toAddOrUpd() {
        long id = getLong("id");
        monthlyReportService.getOne(request, getModelClass(), id);
        monthlyReportService.getTimeInterval(); //设置时间
        todayTaskService.getUserList();
        return "a/oa/work/monthlyreport/monthlyreport_update";
    }
    @ApiOperation(value = "添加/修改工作月报", notes = "")
    @RequestMapping(path = "/addOrUpdate", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    @SubmitRequestIntercept(desp = "提交拦截验证")
    public Object addOrUpd(@Valid MonthlyReportModel model) {
        return monthlyReportService.addOrUpdate(model);
    }

    @ApiOperation(value = "删除工作月报", notes = "")
    @RequestMapping(path = "/del", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    public Object del() {
        long id = getLong("id");
        Result result = monthlyReportService.remove(getModelClass(), id);
        return Web.Response.result(result);
    }
}